library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.6     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.4     ✓ stringr 1.4.0
## ✓ readr   2.0.0     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(ggplot2)
library(here)
## here() starts at /Users/feliciacruz/Documents/MEDS/Winter_22/EDS_240/data-viz-final
library(janitor)
## 
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(stringr)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
cots <- read_csv(here("cots.csv")) %>% 
  clean_names()
## Rows: 1008 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Site, Habitat
## dbl (3): Year, Transect, COTS
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
cots$year <- as.factor(cots$year)
cots_summary <- cots %>%
  group_by(site, year) %>% 
  summarize(total = sum(cots))
## `summarise()` has grouped output by 'site'. You can override using the `.groups` argument.
# make totals df 
totals <- cots_summary %>% 
  group_by(year) %>% 
  summarize(total_count = sum(total)) 
g <- ggplot(data = cots_summary, aes(x = as.factor(year), y = total, fill = site)) +
  geom_col(position = "stack") +
  labs(title = "Crown of Thorns Sea Stars",
       subtitle = "Moorea, French Polynesia (2005-2018)",
       fill = "Site",
       x = "year") +
  scale_y_continuous(breaks = seq(0, 150, by = 25)) +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1),
        panel.grid.major.x = element_blank(), panel.grid.minor.x = element_blank()) +
  scale_fill_brewer(palette = "Set2") 

g

ggplotly(g,
         tooltip = c("total", "site")) %>% 
  layout(title = list(text = paste0('Crown of Thorns Sea Stars',
                                    '<br>',
                                    '<sup>',
                                    'Moorea, French Polynesia (2005-2018)',
                                    '</sup>')))

COTS Raw Counts Plot

g_2 <- ggplot(data = cots_summary, aes(x = as.factor(year), y = total, fill = site)) +
  geom_col(position = "stack") +
  labs(title = "Crown of Thorns Sea Stars",
       subtitle = "Moorea, French Polynesia (2005-2018)",
       fill = "Site",
       x = "Year",
       y = "Total") +
  scale_y_continuous(breaks = seq(0, 150, by = 25)) +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1),
        panel.grid.major.x = element_blank(), panel.grid.minor.x = element_blank(),
        axis.title.x = element_text(size=14),
        axis.title.y = element_text(size = 14),
        plot.title = element_text(size = 16)) +
  #scale_fill_brewer(palette = "Set2") +
  scale_fill_manual(values = c("#40B5AD", "#87CEEB", "#4682B4", "#6F8FAF", "#9FE2BF", "#6495ED")) +
  geom_text(
    aes(label = stat(y), group = year), 
    stat = 'summary', fun = sum, vjust = -1, nudge_y = 2)

ggplotly(g_2,
         tooltip = c("total", "site"))  %>% 
  layout(title = list(text = paste0('Crown of Thorns Sea Stars',
                                    '<br>',
                                    '<sup>',
                                    'Moorea, French Polynesia (2005-2018)',
                                    '</sup>')))

Figure 1: Total raw counts of Crown of Thorns Sea Stars at the six LTER research sites surrounding Moorea

group by site & year , sum total observations / 1000 -> annual site mean density

cots_density <-  cots %>% 
  group_by(site, year) %>% 
  summarize(density = (sum(cots)/1000)) # this should give annual site mean density 
## `summarise()` has grouped output by 'site'. You can override using the `.groups` argument.

Density Plot

ggplot(data = cots_density, aes(x = year, y = density)) +
  geom_point(aes(color = site)) +
  geom_line(aes(group = site, color = site)) +
  facet_wrap(~site) +
  labs(title = "Crown of Thorns Sea Stars - Annual Site Densities",
       subtitle = "Moorea, French Polynesia (2005 - 2018)",
       y = "Density (count/1000 m^2)",
       x = "Year",
       color = "Site") +
  #scale_x_discrete(labels = c("", 2006, "", 2008, "", 2010, "", 2012, "", 2014, "", 2016, "", 2018)) +
  scale_color_manual(values = c("#40B5AD", "#87CEEB", "#4682B4", "#6F8FAF", "#9FE2BF", "#6495ED")) +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1),
        panel.grid.major.x = element_blank(), panel.grid.minor.x = element_blank(),
        panel.grid.minor.y = element_blank(),
        axis.title.x = element_text(size=14),
        axis.title.y = element_text(size = 14),
        plot.title = element_text(size = 16))
Figure 2: Annual site densities for Crown of Thorns Sea Star density at the six LTER sites surrounding Moorea

Figure 2: Annual site densities for Crown of Thorns Sea Star density at the six LTER sites surrounding Moorea


From Figure 1, we can see that Moorea was hit with a huge outbreak of Crown of Thorns Sea Stars between 2007 and 2009. These sea stars feed on coral and can have numerous effects on the coral reef ecosystems surrounding Moorea, which is why tracking the historical occurrences is valuable to various research projects concerned with the health of the coral reefs of Moorea.

Figure 2 shows us the annual site density of Crown of Thorns Sea Stars per 1000 square meters at each of the six LTER sites surrounding the island. Densities are calculated using the raw counts at each site for a given year divided by 1000 since there are four 250 m^2 transects for each site. This builds upon Figure 1 to more clearly highlight how sites 2, 4, and 6 saw the most Crown of Thorns Sea Stars by density during the outbreak.